package com.price.sample

import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.price.common.extend.doOnClick
import com.price.common.extend.logError
import com.zp.common.R

class SimpleAdapter :Adapter<SimpleAdapter.HolderView>() {

    val beanList= ArrayList<Int>()
    fun submitList(list:List<Int>){
        beanList.addAll(list)
        notifyDataSetChanged()
    }

    class HolderView(itemView: View) :ViewHolder(itemView){
        val tv:TextView=itemView.findViewById(R.id.tv_title)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HolderView {
        val view=LayoutInflater.from(parent.context).inflate(R.layout.item_text,parent,false)
        return HolderView(view)
    }

    override fun getItemCount(): Int =beanList.size

    override fun onBindViewHolder(holder: HolderView, position: Int) {

        holder.tv.setText(beanList[position])

        holder.itemView.tag=beanList[position]
        holder.itemView.doOnClick {
            doOnClick?.onClick(holder.itemView)
        }
    }


    var doOnClick :OnClickListener?=null


}